home *** CD-ROM | disk | FTP | other *** search
/ QRZ! Ham Radio 1 / QRZ Ham Radio Callsign Database - December 1993.iso / ucsd / packet / tcpip / amiga / asrc29k.lha / rspfdump.c < prev    next >
Encoding:
C/C++ Source or Header  |  1993-01-08  |  2.9 KB  |  123 lines

  1. #include <stdio.h>
  2. #include "global.h"
  3. #include "mbuf.h"
  4. #include "netuser.h"
  5. #include "internet.h"
  6. #include "ip.h"
  7. #include "rspf.h"
  8. #include "trace.h"
  9.  
  10. /* Dump an RSPF packet */
  11. void rspf_dump(fp,bpp,source,dest,check)
  12. FILE *fp;
  13. struct mbuf **bpp;
  14. int32 source,dest;
  15. int check;        /* If 0, bypass checksum verify */
  16. {
  17.     union rspf rspf;
  18.     struct pseudo_header ph;
  19.     int16 csum;
  20.     int sync;
  21.  
  22.     if(bpp == NULLBUFP || *bpp == NULLBUF)
  23.         return;
  24.  
  25.     fprintf(fp,"RSPF: ");
  26.  
  27.     /* Compute checksum */
  28.     ph.source = source;
  29.     ph.dest = dest;
  30.     ph.protocol = RSPF_PTCL;
  31.     ph.length = len_p(*bpp);
  32.     if((csum = cksum(&ph,*bpp,ph.length)) == 0)
  33.         check = 0;    /* No checksum error */
  34.  
  35.     ntohrspf(&rspf,bpp);
  36.  
  37.     if(rspf.hdr.version != RSPF_VERSION)
  38.         fprintf(fp,"version %u ",rspf.hdr.version);
  39.     switch(rspf.hdr.type){
  40.     case RSPF_FULLPKT:
  41.         if(rspf.pkthdr.csum == 0)
  42.         check = 0;
  43.         fprintf(fp,"type ROUTING UPDATE ");
  44.         if(rspf.pkthdr.fragtot != 1)
  45.         fprintf(fp,"fragment %u frag total %u ",rspf.pkthdr.fragn,
  46.                rspf.pkthdr.fragtot);
  47.         if(rspf.pkthdr.sync != 4)
  48.         fprintf(fp,"sync %u ",rspf.pkthdr.sync);
  49.         fprintf(fp,"nodes %u id %u",rspf.pkthdr.nodes,rspf.pkthdr.envid);
  50.         if(check)
  51.         fprintf(fp," CHECKSUM ERROR (%u)",csum);
  52.         fprintf(fp,"\n");
  53.         if(rspf.pkthdr.sync != 0)
  54.         sync = rspf.pkthdr.sync - 4;
  55.         else
  56.         sync = len_p(*bpp);
  57.         if(sync % 5 != 0){
  58.         fprintf(fp,"      %d bytes\n",sync);
  59.         pullup(bpp,NULLCHAR,sync);
  60.         sync = 0;
  61.         }
  62.         rspfnodedump(fp,bpp,sync / 5);
  63.         break;
  64.     case RSPF_RRH:
  65.         if(rspf.rrh.csum == 0)
  66.         check = 0;
  67.         fprintf(fp,"type RRH seq 0x%04x flags %d",rspf.rrh.seq,rspf.rrh.flags);
  68.         if(check)
  69.         fprintf(fp," CHECKSUM ERROR (%u)",csum);
  70.         fputc('\n',fp);
  71.         break;
  72.     default:
  73.         fprintf(fp,"Unknown packet type\n");
  74.     }
  75. }
  76.  
  77. void
  78. rspfnodedump(fp,bpp,adjcnt)
  79. FILE *fp;        /* uses tputs() if NULLFILE */
  80. struct mbuf **bpp;    /* routing update without packet header */
  81. int adjcnt;        /* number of links before first node header */
  82. {
  83.      int c, links = 0;
  84.      char buf[128];
  85.      struct rspfnodeh nodeh;
  86.      struct rspflinkh linkh;
  87.      *buf = '\0';
  88.      for(;;) {
  89.       if(*buf != '\0') {
  90.            if(fp != NULLFILE)
  91.             fputs(buf,fp);
  92.            else
  93.             tprintf(buf);
  94.            *buf = '\0';
  95.       }
  96.       if(len_p(*bpp) == 0)
  97.            break;
  98.       if(adjcnt){
  99.            if((c = PULLCHAR(bpp)) == -1)
  100.             break;
  101.            sprintf(buf,"            %s/%u\n",inet_ntoa(pull32(bpp)),c);
  102.            adjcnt--;
  103.            continue;
  104.       }
  105.       if(links){
  106.            if(ntohrspflink(&linkh,bpp) == -1)
  107.             break;
  108.            sprintf(buf,"      horizon %u ERP factor %u cost %u adjacencies %u\n",
  109.                linkh.horizon,linkh.erp,linkh.cost,linkh.adjn);
  110.            adjcnt = linkh.adjn;
  111.            links--;
  112.            continue;
  113.       }
  114.       if(ntohrspfnode(&nodeh,bpp) == -1)
  115.            break;
  116.       sprintf(buf,"      Reporting Router: %s Seq %u Subseq %u links %u\n",
  117.           inet_ntoa(nodeh.addr),(int16)nodeh.seq,nodeh.subseq,
  118.           nodeh.links);
  119.       links = nodeh.links;
  120.      }
  121. }
  122.  
  123.